package com.wyu.dao;

import com.alibaba.druid.util.JdbcUtils;
import com.wyu.pojo.SC;
import com.wyu.pojo.YG;
import com.wyu.util.GetCt;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

public class SelectSCDaoImpl implements SelectSCDao {
    @Override
    public List<SC> searchscbh(String scbh) {
        QueryRunner qr = new QueryRunner();
        Connection ct = null;
        SC sc = null;
        //获得数据库连接，德鲁伊数据源
        try {
            ct = GetCt.getConnection();
            String sql = "select * from scb where scbh like ?;";
            List<String> list4 = new ArrayList<>();
            if(scbh!=null){
                list4.add("%"+scbh+"%");
            }if (scbh==null){
                return null;
            }
            BeanListHandler<SC> handler = new BeanListHandler(SC.class);
            List<SC> list3 = qr.query(ct,sql,handler,list4.toArray());
            System.out.println(list3);
            return list3;
        } catch (Exception exception){
            exception.printStackTrace();
        }finally {
            JdbcUtils.close(ct);
        }
        return null;
    }

    @Override
    public List<SC> searchscmc(String scmc) {
        QueryRunner qr = new QueryRunner();
        Connection ct = null;
        SC sc = null;
        //获得数据库连接，德鲁伊数据源
        try {
            ct = GetCt.getConnection();
            String sql = "select * from scb where scmc like ?;";
            List<String> list5 = new ArrayList<>();
            if(scmc!=null){
                list5.add("%"+scmc+"%");
            }if (scmc==null){
                return null;
            }
            BeanListHandler<SC> handler = new BeanListHandler(SC.class);
            List<SC> list4 = qr.query(ct,sql,handler,list5.toArray());
            System.out.println(list4);
            return list4;
        } catch (Exception exception){
            exception.printStackTrace();
        }finally {
            JdbcUtils.close(ct);
        }
        return null;
    }
}
